home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Snippets / SuperSplash 1.0d1 / sources / stdHighLevelApple.cp < prev    next >
Text File  |  1995-10-03  |  4KB  |  157 lines

  1. /* 
  2. *    stdHighLevelApple.cp
  3. *
  4. *    SuperSplash
  5. *    ^^^^^^^^^^^
  6. *    4 required high-level AE's
  7. *    Uses UPP's for future PowerMac compatibility
  8. *
  9. *    © Andrew Nemeth (where applicable), Warrimoo Australia 1994, 1995
  10. *    aznemeng@zeta.org.au
  11. *
  12. *    File created:        19 Mar 95.
  13. *    Modified:            19, 22, 27 Mar;
  14. *                    15 Jun;
  15. *                    3 Oct 95.
  16. */
  17.  
  18.  
  19. #include    "stdHighLevelApple.h"                            //    Application High-Level AE
  20. #include    "gVariables.h"                                    //    Global variable defn & 'externs'
  21.  
  22. #include     <AppleEvents.h>                                //    High level AE
  23. #include     <gestaltEqu.h>                                    //    Gestalt
  24.  
  25.  
  26.  
  27.  
  28. //    LOCAL function prototypes…
  29. //
  30. static pascal OSErr    doOpenApp        ( AppleEvent *, AppleEvent *, long );
  31. static pascal OSErr    doOpenDoc        ( AppleEvent *, AppleEvent *, long );
  32. static pascal OSErr    doPrintDoc    ( AppleEvent *, AppleEvent *, long );
  33. static pascal OSErr    doQuitApp        ( AppleEvent *, AppleEvent *, long );
  34.  
  35.  
  36. //    FILE GLOBALS
  37. //
  38. AEEventHandlerUPP    guppOpenApp, 
  39.                 guppOpenDoc, 
  40.                 guppPrintDoc, 
  41.                 guppQuitApp;
  42.  
  43. //    N.B. These MUST be declared as global because
  44. //    they have to be viable for the life of the
  45. //    program in native PPC apps!
  46.  
  47.  
  48.  
  49. void        highLevelEventInit( void )
  50. //
  51. //    Function to initialise 
  52. //    4 required AppleEvent handlers 
  53. //
  54. {
  55.     OSErr            myErr = noErr;
  56.  
  57.     //    Install the High Level event handlers for the 4 main AE's.
  58.     //    If there's a problem with any of them, drop into Jasik Land…
  59.  
  60.     guppOpenApp = NewAEEventHandlerProc( doOpenApp );
  61.     myErr = ::AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,
  62.                             guppOpenApp,  0L, FALSE );
  63.     if ( myErr != noErr )
  64.         {
  65.         ::SysBeep(1);
  66.         ::DebugStr( "\pInstall of kAEOpenApplication handler failed" );
  67.         }
  68.     
  69.     guppOpenDoc = NewAEEventHandlerProc( doOpenDoc );
  70.     myErr = ::AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments,
  71.                             guppOpenDoc,  0L, FALSE );
  72.     if ( myErr != noErr )
  73.         {
  74.         ::SysBeep(1);
  75.         ::DebugStr( "\pInstall of kAEOpenDocuments handler failed" );
  76.         }
  77.     
  78.     guppPrintDoc = NewAEEventHandlerProc( doPrintDoc );
  79.     myErr = ::AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments,
  80.                             guppPrintDoc,  0L, FALSE );
  81.     if ( myErr != noErr )
  82.         {
  83.         ::SysBeep(1);
  84.         ::DebugStr( "\pInstall of kAEPrintDocuments handler failed" );
  85.         }
  86.     
  87.     guppQuitApp = NewAEEventHandlerProc( doQuitApp );
  88.     myErr = ::AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,
  89.                             guppQuitApp,  0L, FALSE );
  90.     if ( myErr != noErr )
  91.         {
  92.         ::SysBeep(1);
  93.         ::DebugStr( "\pInstall of kAEQuitApplication handler failed" );
  94.         }
  95. }
  96.  
  97.  
  98. pascal OSErr     doOpenApp( AppleEvent         * ptraeEvent, 
  99.                         AppleEvent    * ptraeReply, 
  100.                         long            lgRefcon )
  101. //
  102. //    The routine called at startup.
  103. //
  104. {
  105. //                                                        silence the compiler warnings!
  106.     if ( lgRefcon || ptraeEvent || ptraeReply )
  107.         NULL;
  108.  
  109.     return( noErr );
  110. }
  111.  
  112.  
  113.  
  114. pascal OSErr     doOpenDoc( AppleEvent         * ptraeEvent, 
  115.                         AppleEvent     * ptraeReply, 
  116.                         long         lgRefcon )
  117. //
  118. //    Not supported.  Just start app instead.
  119. //
  120. {
  121.     return( doOpenApp( ptraeEvent, ptraeReply, lgRefcon ) );
  122. }
  123.  
  124.  
  125.  
  126. pascal OSErr     doPrintDoc( AppleEvent         * ptraeEvent, 
  127.                         AppleEvent     * ptraeReply, 
  128.                         long         lgRefcon )
  129. //
  130. //    Print not supported by this application
  131. //
  132. {
  133. //                                                        silence the compiler warnings!
  134.     if ( lgRefcon || ptraeEvent || ptraeReply )
  135.         NULL;
  136. //                                                        exit gracefully
  137.     gptrGlobalsRec->boolDone = TRUE;
  138.     return( noErr );
  139. }
  140.  
  141.  
  142.  
  143. pascal OSErr     doQuitApp( AppleEvent         * ptraeEvent, 
  144.                         AppleEvent    * ptraeReply, 
  145.                         long         lgRefcon )
  146. //
  147. //    Functions to perform on 'quit' Apple Event.
  148. //
  149. {
  150. //                                                        silence the compiler warnings!
  151.     if ( lgRefcon || ptraeEvent || ptraeReply )
  152.         NULL;
  153.  
  154.     gptrGlobalsRec->boolDone = TRUE;
  155.     return( noErr );
  156. }
  157.